﻿package org.davialexandre.asmtp 
{
	import flash.events.EventDispatcher;
	import flash.events.Event;
	import flash.net.Socket;
	import org.davialexandre.asmtp.events.SMTPResponseEvent;
	
	/**
	 * ...
	 * @author DefaultUser (Tools -> Custom Arguments...)
	 */
	public class SMTPConnector extends EventDispatcher
	{
		
		private var _socket:Socket;
		private var _server:SMTPServer;
		
		public function SMTPConnector(server:SMTPServer) 
		{
			_server = server;
			addEventListener(Event.CONNECT, connectHandler);
		}
		
		public function get server():SMTPServer {
			return new SMTPServer(_server.host, _server.port);
		}
		
		public function set server(value:SMTPServer):void {
			_server = value;
		}
		
		public function connect():void {
			_socket = new Socket(server.host, server.port);
		}
		
		private function connectHandler(evt:Event):void {
			dispatchEvent(new SMTPResponseEvent(SMTPResponseEvent.CONNECTED, SMTPResponseCode.SERVICE_READY));
		}
		
	}
	
}